import java.io.FileNotFoundException;
import java.io.IOException;

public class Jake {
    public static void main(String[] args) {
        try {
            String targetName = args.length > 0 ? args[0] : "default";
            System.out.println("=== Jake 构建工具 ===");
            System.out.println("当前执行目标：" + targetName + "\n");

            JakespecParser parser = new JakespecParser();
            Jakespec jakespec = parser.parse();

            TargetExecutor executor = new TargetExecutor(jakespec);
            executor.executeTarget(targetName);

            System.out.println("\n=== 构建成功！===");

        } catch (FileNotFoundException e) {
            System.err.println("\n❌ 错误：Jakespec文件未找到 - " + e.getMessage());
            System.exit(1);
        } catch (IllegalArgumentException e) {
            System.err.println("\n❌ 错误：参数非法 - " + e.getMessage());
            System.exit(1);
        } catch (RuntimeException e) {
            System.err.println("\n❌ 构建失败: " + e.getMessage());
            e.printStackTrace();
            System.exit(1);
        } catch (IOException | InterruptedException e) {
            System.err.println("\n❌ 系统错误: " + e.getMessage());
            e.printStackTrace();
            System.exit(1);
        }
    }
}